<section class="content">

    {!! $grid !!}

</section>
<script src="{{ asset('style/js/layer/layer.js') }}"></script>
<script>
    $(function(){
        $('.datatree-item').each(function(i, ele){
            var self = $(ele);
            var id = self.data('id');
            var create_url = "{{ url('admin/system_manage/menu/create') }}?pid="+id;
            var edit_url = "{{ url('admin/system_manage/menu') }}/"+id;
            var buttonData = {
                create: '<a href="'+create_url+'" class="btn btn-success btn-xs menu-create">添加子节点</a>&nbsp;',
                edit: '<a href="'+edit_url+'" class="btn btn-info btn-xs menu-edit">修改</a>&nbsp;',
                delete: '<button type="button" data-id="'+id+'" class="btn btn-warning btn-xs menu-delete">删除</button>'
            };
            self.children('.datatree-handle').append("<div class='edit pull-right'></div>");
            if(self.children('.datatree-handle').children('div.edit').length == 1){
                self.children('.datatree-handle').children('div.edit').html(buttonData.create + buttonData.edit + buttonData.delete);
            }
        });

        $('.menu-delete').on('click', function(){
            var self = $(this);
            layer.confirm('你确定要删除吗？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                var id = self.data('id');
                var data = {
                    '_method': 'delete',
                    '_token': "{{ csrf_token() }}"
                };
                $.post("{{ url('admin/system_manage/menu') }}/"+ id, data, function(data){
                    if(data.msg == 'delete success!'){
                        location.reload();
                    }else{
                        layer('删除失败！',{'icon': 5});
                    }
                });
            }, function(){
                layer.close();
            });
        });
    });
</script>
